<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>设备管理</title>
	<meta name="decorator" content="default"/>
	<%@ include file="/WEB-INF/views/include/dialog.jsp"%>
	<script type="text/javascript">
	$(document).ready(function() {
		$("#btnExport").click(function(){
			top.$.jBox.confirm("确认要导出学生数据吗？","系统提示",function(v,h,f){
				if(v=="ok"){
					$("#searchForm").attr("action","${ctx}/dd/ddEquipment/export");
					$("#searchForm").submit();
				}
			},{buttonsFocus:1});
			top.$('.jbox-body .jbox-icon').css('top','55px');
		});
		$("#btnImport").click(function(){
			$.jBox($("#importBox").html(), {title:"导入数据", buttons:{"关闭":true}, 
				bottomText:"导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"});
		});
	});
		function page(n,s){
			if(n) $("#pageNo").val(n);
			if(s) $("#pageSize").val(s);
			$("#searchForm").attr("action","${ctx}/dd/ddEquipment/list");
			$("#searchForm").submit();
	    	return false;
	    };
	    function setDowmUrl(){
			var url='${ctxStatic}'+"/xls/设备表.xlsx";
			location.href =url;
	    };
		function showDialog(id) {
			$("#id").val(id);
			/* $("#name").val(eqname);
			$("#parameter").val(parameter); */
			$("#schoolId").val();
			$("#classroomId").val();
			$("#dialog").dialog({
				modal : true
			}, {
				title : "绑定操作"
			}, {
				show : {
					effect : 'drop',
					direction : 'up'
				}
			}, {
				width : "500"
			}, {
				height : "250"
			});
		};
	</script>
</head>
<body>
<div id="importBox" class="hide">
		<form id="importForm" action="${ctx}/dd/ddEquipment/import" method="post" enctype="multipart/form-data"
			class="form-search" style="padding-left:20px;text-align:center;" onsubmit="loading('正在导入，请稍等...');"><br/>
			<input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
			<input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
			<%-- <a href="${ctx}/dd/ddStudent/import/template">下载模板</a> --%>
				<a id="dowmTable" href="javascript:;" onclick="setDowmUrl();">下载模板</a>
		</form>
	</div>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/dd/ddEquipment/">设备列表</a></li>
		<shiro:hasPermission name="dd:ddEquipment:edit"><li><a href="${ctx}/dd/ddEquipment/form">添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="ddEquipment" action="${ctx}/dd/ddEquipment/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<ul class="ul-form">
			<li><label>设备名称：</label>
				<form:input path="name" htmlEscape="false" maxlength="200" class="input-medium"/>
			</li>
			<li><label>学校名称：</label>
				<form:input path="schoolName" htmlEscape="false" maxlength="200" class="input-medium"/>
			</li>
			<li><label>教室名称：</label>
				<form:input path="classroomName" htmlEscape="false" maxlength="200" class="input-medium"/>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
				<input id="btnImport" class="btn btn-primary" type="button" value="导入"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>设备名称</th>
				<th>所属学校</th>
				<th>所属教室</th>
				<th>参数</th>
				<shiro:hasPermission name="dd:ddEquipment:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="ddEquipment">
			<tr>
				<td><a href="${ctx}/dd/ddEquipment/form?id=${ddEquipment.id}">
					${ddEquipment.name}
				</a></td>
			    <td>${ddEquipment.schoolName}</td> 
			    <td>${ddEquipment.classroomName}</td>
			    <td>${ddEquipment.parameter}</td>
				<shiro:hasPermission name="dd:ddEquipment:edit"><td>
    				<a href="${ctx}/dd/ddEquipment/form?id=${ddEquipment.id}" title="设备信息管理">修改</a>
    				 <a href="javascript:;" onclick="showDialog('${ddEquipment.id}');" title="相关绑定">绑定</a>
					<a href="${ctx}/dd/ddEquipment/delete?id=${ddEquipment.id}" onclick="return confirmx('确认要删除该单表吗？', this.href)">删除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	
	
	<div id="dialog" style="display:none;">
		<form:form class="form-horizontal" role="form" id="f_bind"
			modelAttribute="ddEquipment" action="${ctx}/dd/ddEquipment/save" method="post">
			<form:input type="hidden" path="id" name="id" />
			<div class="clearfix" style="height: 20px"></div>
			<div class="control-group">
				<label class="control-label"><b style="color: red; font-size: large">*</b>学校:</label> 
					<form:select path="schoolId" class="input-mini form-control required ">
					            <form:option value="">请选择</form:option>		
								<form:options items="${fns:getSchoolNameList()}" itemLabel="name"								
									itemValue="id" htmlEscape="false" />
							</form:select> 
							
			</div>
			<div class="control-group">
			<br>
					<label class="control-label"><b style="color: red; font-size: large">*</b>教室:</label> 
					 <form:select path="classroomId" class="input-mini form-control required ">
					            <form:option value="">请选择</form:option>		
								<form:options items="${fns:getClassRoomNameList(school)}" itemLabel="name"
									itemValue="id" htmlEscape="false" />
							</form:select>
			</div>
			<div class="clearfix" style="height: 10px"></div>
			<div class="control-group" style="width: 15%; margin:auto;">
				<input type=submit id="bSubmit" class="" value="提交" />
			</div>
		</form:form>
	</div>
	<script>
		$(function() {
			$('#bindSubmit').click(function() {//点击按钮提交
				$.ajax({
					url : "${ctx}/dd/ddEquipment/bind",
					data : $("#f_bind").serialize(),
					type : "post",
					success : function(data) {//ajax返回的数据
						alert(data);
						$("#dialog").dialog('close');
					},
					error : function(data) {//ajax返回的数据
						alert(data);
						$("#dialog").dialog('close');
					}
				});
			});

		});
	</script>
</body>
</html>